package com.leetcode.LC;

public class LC1351 {
    public int countNegatives(int[][] grid) {
        //从后往前遍历，遇到正数就跳出

        int count = 0;
        for (int length = grid.length - 1; length >= 0; length--) {
            for (int i = grid[0].length - 1; i >= 0; i--) {
                if (grid[length][grid[0].length - 1] >= 0) {
                    return count;
                } else if (grid[length][i] < 0) {
                    count++;
                } else {
                    break;
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new LC1351().countNegatives(new int[][]{{4, 3, 2, -1}, {3, 2, 1, -1}, {1, 1, -1, -2}, {-1, -1, -2, -3}}));
    }
}
